package br.com.cotec.dao.impl;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Example;

import br.com.cotec.dao.FileiraDao;
import br.com.cotec.model.Fileira;

public class FileiraDaoImpl extends GenericDaoImpl<Fileira, Serializable> implements FileiraDao{
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public Fileira save(Fileira object){
		em.persist(object);
		
		return object;
	}
	
	/**
	 * 
	 * {@inheritDoc}
	 * 
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<Fileira> getByExample(Fileira fileira) {
		Session hibernateSession = (Session) em.getDelegate();
		Criteria criteria = hibernateSession.createCriteria(Fileira.class, "fil").add(Example.create(fileira));
		criteria.createCriteria("fil.sala", Criteria.INNER_JOIN).add(Example.create(fileira.getSala()));
		return (List<Fileira>)criteria.list();
	}
}